<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

// import application view
jimport('joomla.application.component.view');

class SyncrViewSites extends JView
{
	public function display($tpl = null)
	{
		$db =& JFactory::getDBO();
		$app =& JFactory::getApplication();
		$params =& JComponentHelper::getParams('com_syncr');
		
		// filters
		$filter_state		= $app->getUserStateFromRequest('com_syncr', 'filter_state', '', 'word');
		$filter_metakeys	= $app->getUserStateFromRequest('com_syncr', 'filter_metakeys', '', 'word');
		$filter_search		= $app->getUserStateFromRequest('com_syncr', 'search',  '', 'string');
		$filter_search		= JString::strtolower($filter_search);
		
		// list ordering
		$lists['order']		= $app->getUserStateFromRequest('com_syncr.filterOrder', 'filter_order', 'name', 'word');
		$lists['orderDirection'] = $app->getUserStateFromRequest('com_syncr.filterOrderDirection', 'filter_order_Dir', 'ASC', 'cmd');
		
		if (strtoupper($lists['orderDirection']) !== 'ASC') {
			$lists['orderDirection'] = 'DESC';
		}
		
		// list filters
		$lists['search']	= $filter_search;
		$lists['state']		= JHTML::_('grid.state', $filter_state);
		
		// data
		$sites =& $this->get('data');
				
		// pagination
		$pagination	=& $this->get('pagination');
		$sitecount	= count($sites);
		$pageOrd	= new JPagination($sitecount, 0, $sitecount);
		
		// assign references
		$this->assignRef('user',		JFactory::getUser());
		$this->assignRef('sites', $sites);
		$this->assignRef('pagination', $pagination);
		$this->assignRef('pageOrd', $pageOrd);
		$this->assignRef('lists', $lists);
		$this->assignRef('sitecount', $sitecount);
		$this->assignRef('params', $params);
		
		
		// set toolbar
		$this->_setToolBar();
		
		// call parent behavior with template
		parent::display($tpl);
	}
	
	private function _setToolBar() {
		JToolBarHelper::title(JText::_('SYNCR_SITES'), 'generic.png');
		JToolBarHelper::addNew();
		JToolBarHelper::editList();
		JToolBarHelper::publishList( );
		JToolBarHelper::unpublishList( );
		JToolBarHelper::deleteList('ARE_YOU_SURE_YOU_WANT_TO_DELETE_THE_SELECTED_SITES');
		JToolBarHelper::preferences('com_syncr', 350);
	}
}